package test2;

import java.util.Arrays;
//最长连续序列
public class demo53 {
    class Solution {
        public int longestConsecutive(int[] nums) {
            if(nums.length == 0) return 0;
            Arrays.sort(nums);
            int len = 1;
            int index1 = 1;
            int i = 0,j = 1;
            while(j<nums.length)
            {
                if(nums[j]-nums[i]==1)
                {
                    index1++;
                    len = Math.max(index1,len);
                }
                else if(nums[j]==nums[i])
                {
                    ;
                }
                else{
                    index1 = 1;
                }
                i++;
                j++;
            }
            return len;
        }
    }
}
